﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data.OleDb;
using System.Data;

namespace Web_HengliSeed.BLL
{
    public class LeaveInfo
    {
        /// <summary>
        /// 回复留言信息
        /// </summary>
        /// <param name="ClassID"></param>
        /// <param name="strClassName"></param>
        /// <param name="strKey"></param>
        /// <param name="strDes"></param>
        /// <returns></returns>
        public static bool EditLeaveMes(string T_LeaveID, string T_ReplyNote)
        {
            try
            {
                string strSql = "  UPDATE T_LeaveInfo SET T_ReplyNote=@T_ReplyNote,T_LeaveFlag=1  WHERE T_LeaveID=@T_LeaveID ";
                OleDbParameter[] parm = { new OleDbParameter("@T_ReplyNote", T_ReplyNote),
                                                           new OleDbParameter("@T_LeaveID", T_LeaveID)};
                return (ClassFile.AccessHelper.ExecuteNonQuery(ClassFile.AccessHelper.ConnectionString, strSql, parm) > 0) ? true : false;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 添加留言信息
        /// </summary>
        /// <param name="ClassID"></param>
        /// <param name="strClassName"></param>
        /// <param name="strKey"></param>
        /// <param name="strDes"></param>
        /// <returns></returns>
        public static bool EditClassMes(string T_LeaveTitle, string T_LeaveNote)
        {
            try
            {
                string strSql = " INSERT INTO  T_LeaveInfo (T_LeaveTitle,T_LeaveNote,T_DateTime,T_LeaveIP) VALUES (@T_LeaveTitle,@T_LeaveNote,@T_DateTime,@T_LeaveIP) ";
                OleDbParameter[] parm = { new OleDbParameter("@T_LeaveTitle", T_LeaveTitle),
                                                           new OleDbParameter("@T_LeaveNote", T_LeaveNote),
                                                           new OleDbParameter("@T_DateTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")),
                                                           new OleDbParameter("@T_LeaveIP", Common.GetMes.GetIp())};
                return (ClassFile.AccessHelper.ExecuteNonQuery(ClassFile.AccessHelper.ConnectionString, strSql, parm) > 0) ? true : false;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 分页获取留言数据
        /// </summary>
        /// <param name="PageIndex"></param>
        /// <param name="PageSize"></param>
        /// <param name="PageCount"></param>
        /// <param name="RecordCount"></param>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public static DataTable GetAllLeaveMes(int PageIndex, int PageSize, out int PageCount, out int RecordCount, string strWhere)
        {
            try
            {
                string strSql = " SELECT * FROM T_LeaveInfo ";
                string strShow = " * ";
                return ClassFile.AccessHelper.ExecutePager(PageIndex, PageSize, "T_LeaveID", strShow, strSql, strWhere, " T_LeaveID DESC ", out PageCount, out RecordCount);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 查看留言信息
        /// </summary>
        /// <param name="strLeaveID"></param>
        /// <returns></returns>
        public static OleDbDataReader GetAllLeaveMes(string strLeaveID)
        {
            try
            {
                OleDbParameter[] parm = { new OleDbParameter("@T_LeaveID", strLeaveID) };
                return ClassFile.AccessHelper.ExecuteReader(ClassFile.AccessHelper.ConnectionString, "  SELECT * FROM T_LeaveInfo WHERE T_LeaveID=@T_LeaveID  ", parm);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 删除指定ID的留言信息
        /// </summary>
        /// <param name="strProClass"></param>
        /// <returns></returns>
        public static bool DelLeaveInfo(string strProID)
        {
            try
            {
                string strSql = string.Format(" DELETE FROM T_LeaveInfo WHERE T_LeaveID in({0}) ", strProID);
                return (ClassFile.AccessHelper.ExecuteNonQuery(ClassFile.AccessHelper.ConnectionString, strSql, null) > 0) ? true : false;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
